//
//  UserInfoViewModel.swift
//  xiaoqiao
//
//  Created by 冷子豪 on 2017/8/17.
//  Copyright © 2017年 冷子豪. All rights reserved.
//

import Foundation

let userInfoViewModel = UserInfoViewModel()

class UserInfoViewModel {
    
    func updateUserInfo(data:Data) -> Int{
        var returnNum = 1
        // 同步Post方式
        
        // 1.创建URL对象
        let url:URL! = URL(string:"\(info.API_URL)/xqjr/house/appHouseUpadteALL")
        
        // 2.创建Request对象
        var urlRequest:URLRequest = URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10)
        
        // 3、设置请求方式为POST，默认是GET
        urlRequest.httpMethod = "POST"
        
        // 4、设置参数
        urlRequest.httpBody = data;
        
        // 5.响应对象
        var response:URLResponse?
        
        // 6.发出请求
        do {
            let received =  try NSURLConnection.sendSynchronousRequest(urlRequest, returning: &response)
            returnNum = try JSONSerialization.jsonObject(with: received, options: JSONSerialization.ReadingOptions.allowFragments) as! Int
        } catch let error{
            print(error.localizedDescription);
        }
        return returnNum
    }
}
